package script;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import tools.UseBrowser_Remote;
import vo.LoginPage;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;

import static org.testng.Assert.assertEquals;

public class PO_OSChina_Login_remote extends UseBrowser_Remote {


    //osc_Login oscl = new osc_Login();

    LoginPage lp = new LoginPage();
    UseBrowser_Remote ubr=new UseBrowser_Remote();

    WebDriver wd;





    @BeforeTest
    public void beforeTest() throws IOException {
       wd=ubr.setupChromeRemote();
    }

    

    @DataProvider(name = "login_data")
    public static Object[][] login_data() {
        return new Object[][]{

                {"James", "james9437974","用户名或密码错误123","hellotest1"},

                {"jamesz2011@126.com", "","密码不能为空","hellotest2"},

                {"", "james9437974","用户名不能为空","hellotest3"},

                {"", "","用户名不能为空","hellotest4"},

                {"jamesz2011@126.com", "james9437974","","hellotest5"},

        };
    }

    @Test(dataProvider = "login_data",dataProviderClass = PO_OSChina_Login_remote.class)

    public void OSC_Login1(String Username, String Password,String exp,String hellotest) throws MalformedURLException {


        System.out.println("my hellotest:----->"+"open1");
        wd.get("http://www.oschina.net/");
        System.out.println("my hellotest:----->"+"open2");
        //wd.findElement(By.linkText("登录")).click();
        LoginPage login = PageFactory.initElements(wd, LoginPage.class);
        login.click_loginlink();




       login.input_login_data(Username,Password);


        WebElement savebox = wd.findElement(By.xpath(lp.savebox));
        boolean flag = savebox.isEnabled();
        boolean flag1 = true;


        login.click_savebox();

        login.click_loginbutton();


        System.out.println("start-test");


        if (isPresentEle(By.xpath(login.NoPasswd),wd)){

            System.out.println("-------------");
            System.out.println("密码为空");
            System.out.println("-------------");
        }
        else if (isPresentEle(By.xpath(login.NoUsername),wd)){

            System.out.println("-------------");
            System.out.println("用户名为空");
            System.out.println("-------------");
        }
        else if (isPresentEle(By.xpath(login.NoUsername_Passwd),wd)){

            System.out.println("-------------");
            System.out.println("用户名、密码均为空");
            System.out.println("-------------");
        }


        else if (isPresentEle(By.xpath(login.Wrong_Username_Password),wd)){

            WebElement Wrong_Username_Password=wd.findElement(By.xpath(login.Wrong_Username_Password));
            String W_U_P=Wrong_Username_Password.getText();
            System.out.println("-------------");
            System.out.println("用户名或密码错误");
           if (W_U_P.equals(exp)){
               System.out.println("用户名或密码错误-----ok");
           }
           else {
               System.out.println("用户名或密码错误-----error");
               takeScreenshot(wd);
               takeScreenshot(wd);
           }

            System.out.println("-------------");
        }
        else if (isPresentEle(By.xpath(login.Rigit_Username_Password),wd)){
            System.out.println("-------------");
            System.out.println("用户名与密码正确");
            System.out.println("-------------");
            System.out.println("666");


        }



        PlaySpeed();



    }


    @AfterClass
    public void closebrowser() {
       wd.quit();

    }






}
